package com.vcaresolution.logistic.service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vcaresolution.logistic.form.SecurityquestionForm;
import com.vcaresolution.logistic.pojo.Securityquestion;
import com.vcaresolution.logistic.to.SecurityquestionTO;;

@Service
public class SecurityquestionServiceImpl extends BaseService implements SecurityquestionService{

	private Securityquestion populateSecurityquestionPojo(SecurityquestionForm securityquestionForm){
		Securityquestion securityquestion = new Securityquestion();
		BeanUtils.copyProperties(securityquestionForm, securityquestion);
		
		return securityquestion;
	}
	
	@Override
	@Transactional
	public void add(SecurityquestionForm securityquestionForm) {
		Securityquestion securityquestion = populateSecurityquestionPojo(securityquestionForm);
		
		getDaoFactory().getUtilityDAO().add(securityquestion);
	}

	@Override
	@Transactional
	public void update(SecurityquestionForm securityquestionForm) {
		Securityquestion securityquestion = populateSecurityquestionPojo(securityquestionForm);
		
		getDaoFactory().getUtilityDAO().update(securityquestion);
	}

	@Override
	@Transactional
	public void delete(SecurityquestionForm securityquestionForm) {
		getDaoFactory().getUtilityDAO().delete(populateSecurityquestionPojo(securityquestionForm));
	}

	@Override
	@Transactional
	public SecurityquestionTO findById(Serializable sqID) {
		Securityquestion securityquestion = (Securityquestion) getDaoFactory().getUtilityDAO().findById(Securityquestion.class,sqID);
		
		SecurityquestionTO securityquestionTO = new SecurityquestionTO();
		BeanUtils.copyProperties(securityquestion, securityquestionTO);
		
		return securityquestionTO; 
	}

	@Override
	@Transactional
	public List<SecurityquestionTO> findByAll() {
		List<Securityquestion> securityquestionList = getDaoFactory().getUtilityDAO().findByAll(Securityquestion.class);
		
		List<SecurityquestionTO> securityquestionFormList = new ArrayList<SecurityquestionTO>();
		
		if( securityquestionList != null && !securityquestionList.isEmpty() ){
			SecurityquestionTO securityquestionTO = null;
			for(Securityquestion securityquestion: securityquestionList){
				securityquestionTO = new SecurityquestionTO();
				
				BeanUtils.copyProperties(securityquestion, securityquestionTO);
				securityquestionFormList.add(securityquestionTO);
			}
		}	
		return securityquestionFormList;
	}
}